<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSamplesTable extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('samples', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('family_id')->comment('家系ID');
            $table->unsignedInteger('family_member_id')->comment('家系成员ID');
            $table->string('bar_code')->unique()->comment('条形码');
            $table->text('note')->nullable()->comment('备注');
            $table->unsignedInteger('sample_type')->comment('样本类型');
            $table->string('transport_method')->nullable()->comment('运输方式(从字典选择)');
            $table->string('deal_method')->nullable()->comment('处理方式(从字典选择)');
            $table->dateTime('sample_date')->nullable()->comment('采样日期');
            $table->string('sampled_by')->nullable()->comment('采样人');
            $table->dateTime('receive_date')->nullable()->comment('接收日期');
            $table->unsignedInteger('received_by')->nullable()->comment('接收人');
            $table->unsignedInteger('salesman')->nullable()->comment('所属销售');
            $table->unsignedInteger('organization')->nullable()->comment('送检机构');
            $table->unsignedInteger('department')->nullable()->comment('送检科室');
            $table->unsignedInteger('doctor')->nullable()->comment('送检医生');
            $table->unsignedTinyInteger('state')->default(0)->comment('样本状态，0:未接收,1:已接收');
            $table->unsignedTinyInteger('order_state')->default(0)->comment('订单状态，0:未开单,1:已开单,2:不开单,3:暂时保留');
            $table->unsignedTinyInteger('is_normal')->default(1)->comment('是否正常，0:不正常,1:正常');
            $table->unsignedTinyInteger('is_qualified')->default(1)->comment('结果，0:不合格,1:合格');
            $table->string('sample_aim')->nullable()->comment('样本用途(从字典选择)');
            $table->unsignedInteger('created_by')->comment('创建者');
            $table->unsignedInteger('updated_by')->comment('更新者');
            $table->string('data_scope')->nullable()->comment('数据域');
            $table->timestamps();

            $table->comment = '样本总表';
            $table->engine = 'InnoDB';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('samples');
    }

}
